import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class CartinfoDialog extends JDialog
{
	public CartinfoDialog(JFrame _parent, Person _person)
	{
		super(_parent, true);
		JPanel p = new JPanel(new BorderLayout());

		this.add(p);

		p.add(new JLabel("Shopping cart for " + _person.toString()), BorderLayout.NORTH);
		p.add(new JList(_person.getCart()), BorderLayout.CENTER);
		
		JPanel p2 = new JPanel();
		p2.add(new JLabel("Total sum to pay: " + _person.getPriceAsString() + "$"), BorderLayout.SOUTH);
		CloseDialogButton cd = new CloseDialogButton(this);
		p2.add(cd);
		p.add(p2, BorderLayout.SOUTH);
		
		this.pack();
		cd.requestFocusInWindow();
	}
	
	private class CloseDialogButton extends JButton
	{
		
		public CloseDialogButton(JDialog d)
		{
			super("Close");
			this.addActionListener(new Listener(d));
		}
		
		private class Listener implements ActionListener
		{
			JDialog d;
			
			public Listener(JDialog d)
			{
				this.d=d;
			}
			public void actionPerformed(ActionEvent e)
			{
				d.setVisible(false);
			}
		}
	}
}
